// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import myUtils from '@/../static/js/myUtils'
const ltshFrame = {
    openFormDialog(baseUrl,row, _this, addDefaultValues) {
        _this.myUtils.appRequest({
            url: baseUrl + '/getFormField',
            method:'post',
            data:{},
            callback:function(data) {
                console.log(data);
                _this.openFormData.formData = {};
                _this.openFormData.formFields = data.content.toolsFields;

                // 添加必填校验
                for(var i=0; i<_this.openFormData.formFields.length; i++) {
                    var formField = _this.openFormData.formFields[i];
                    if(formField.isRequired) {
                        _this.openFormData.formRules[formField.name] = [{ required: true, message: '请输入' + formField.label, trigger: 'change' }];
                    }
                }
                

                if(addDefaultValues != null) {
                    for(var i=0;i<addDefaultValues.length;i++) {
                        var addDefaultValue = addDefaultValues[i];
                        _this.openFormData.formData[addDefaultValue.name] = addDefaultValue.value;
                    }
                }
                if(row!= null) {
                    _this.myUtils.appRequest({
                        url: baseUrl + '/getById',
                        method:'post',
                        data:{id:row.id},
                        callback:function(data) {
                            console.log(data);
                            _this.openFormData.formData = data.content;
                            _this.showForm();
                        },
                        catch: function(res) {
                            console.log(res);
                        }
                    }, _this);
                } else {
                    _this.showForm();
                    
                }
               
            },
            catch: function(res) {
                console.log(res);
            }
        }, _this);
    },
    delItem(baseUrl,row, _this) {
      _this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            _this.myUtils.appRequest({
                url: baseUrl + '/delete',
                method:'post',
                data:{id:row.id},
                callback:function(data) {
                    _this.$message({
                        type: 'success',
                        message: data.message
                    });
                    _this.$emit('loadData');
                },
                catch: function(res) {
                    console.log(res);
                }
            }, _this);
        }).catch(() => {
          
        });
    }
}
export default ltshFrame